package com.xpgk.mvc.bsendMessage;

import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import jodd.typeconverter.Convert;
import net.greghaines.jesque.Job;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;


/**
 * 短信发送队列
 * @author luojh
 *
 */
public class SMSAction implements Runnable{
	
	public static final String ACTION = "SMSAction";
	
	//private static final Logger log = Logger.getLogger(SMSAction.class);
	private static String URL = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
	
	private String ip;
	private String mobile;
	private String content;
	
	public SMSAction(String mobile,String content,String ip){
		this.mobile = mobile;
		this.content = content;
		this.ip = ip;
	}
	
	@Override
	public void run() {
		HttpRequest request = HttpRequest.post(URL);
		request.form("account", JpxtConstants.sms_account);
		request.form("password", JpxtConstants.sms_password);
		request.form("mobile", mobile);
		request.form("content", content);
		HttpResponse resp = request.send();
//		Document document = Jsoup.parse(resp.bodyText());
//		Element codeElement = document.select("code").get(0);
//		Element msgElement = document.select("msg").get(0);
//		Element smsidElement = document.select("smsid").get(0);
//		int tCode = codeElement == null ? 0 : Convert.toIntValue(codeElement.html(),0);
//		String msg = msgElement == null ? "" : msgElement.html();
//		int smsId = smsidElement == null ? 0 : Convert.toIntValue(smsidElement.html(),0);
//		SmsStatus status = new SmsStatus(tCode, msg, smsId);
		//log.info("ip:"+ip+",向"+mobile+"发送短信:"+content+"。发送状态:"+status.toString());
	}

	public static String getCode(String code){
		//return "您的效验码是：【"+code+"】。请不要把效验码泄露给其他人。如非本人操作，可不用理会！";
		return "您的效验码是：【我爱你中国】。请不要把效验码泄露给其他人。如非本人操作，可不用理会！";
	}
	public static String getTrainCode(String code,String time,String course){
		return "您的练习使用码是：【"+code+"】。请于【"+time+"】准时到达相关场地进行【"+course+"】练习。";
	}
	public static String getExamCode(String code,String time,String course){
		return "您的模拟考试使用码是：【"+code+"】。请于【"+time+"】准时到达相关场地进行【"+course+"】模拟考试。";
	}
	
	public static Job getJob(String mobile,String content,String ip){
		return new Job(ACTION,mobile,content,ip);
	}
}
